const std = @import("std");
const hellozig = @import("hellozig");

pub fn main() !void {
    // Prints to stderr, ignoring potential errors.
    std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
    try hellozig.bufferedPrint();
    const result = hellozig.add(10, 20);
    std.log.info("10 + 20 = {d}\n", .{result});
}

//
// pub fn main2() !void {
//     var arena_state = std.heap.ArenaAllocator.init(std.heap.page_allocator);
//     defer arena_state.deinit();
//     const arena = arena_state.allocator();

//     const self_exe_dir_path = try std.fs.selfExeDirPathAlloc(arena);
//     var self_exe_dir = try std.fs.cwd().openDir(self_exe_dir_path, .{});
//     defer self_exe_dir.close();

//     const word = try self_exe_dir.readFileAlloc("word.txt", arena, 1000);

//     var stdout_buffer: [1000]u8 = undefined;
//     var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
//     const stdout = &stdout_writer.interface;

//     try stdout.print("Hello {s}\n", .{word});
//     try stdout.flush();
// }

//
// const word_content = @embedFile("word");
// pub fn main3() !void {
//     std.log.info("Hello {s}\n", .{word_content});
// }

//
// const Person = @import("person").Person;
// pub fn main4() !void {
//     const p: Person = .{};
//     std.log.info("Hello {any}\n", .{p});
// }

//
// const root = @import("root.zig");
// pub fn main5() !void {
//     std.log.info("Hello {d}\n", .{root.add(10, 20)});
// }

//
// const Protocol = @import("protocol.zig");
// pub fn main6() !void {
//     const header = try std.io.getStdIn().reader().readStruct(Protocol.Header);
//     std.debug.print("header: {any}\n", .{header});
// }

//
test "simple test" {
    const gpa = std.testing.allocator;
    var list: std.ArrayList(i32) = .empty;
    defer list.deinit(gpa); // Try commenting this out and see if zig detects the memory leak!
    try list.append(gpa, 42);
    try std.testing.expectEqual(@as(i32, 42), list.pop());
}

test "fuzz example" {
    const Context = struct {
        fn testOne(context: @This(), input: []const u8) anyerror!void {
            _ = context;
            // Try passing `--fuzz` to `zig build test` and see if it manages to fail this test case!
            try std.testing.expect(!std.mem.eql(u8, "canyoufindme", input));
        }
    };
    try std.testing.fuzz(Context{}, Context.testOne, .{});
}
